package com.snap.vseries.analyze;

import org.apache.commons.math3.analysis.UnivariateFunction;
import org.apache.commons.math3.exception.DimensionMismatchException;
import org.apache.commons.math3.exception.NullArgumentException;
import org.apache.commons.math3.util.FastMath;

/**
 * 双S函数,忽略坡度，除以基数的倍率版，
 */
public class DoubleSigmoidMulti implements UnivariateFunction {

    private final double c;
    private final double d;
    private final double e;
    private final double f;
    private final double g;

    public DoubleSigmoidMulti(double... params) {
        if (params == null) {
            throw new NullArgumentException();
        }
        if (params.length != 7) {
            throw new DimensionMismatchException(params.length, 7);
        }
        this.c = params[2] / params[0];
        this.d = params[3];
        this.e = params[4];
        this.f = params[5];
        this.g = params[6];
    }

    @Override
    public double value(double x) {
        return 1 + c / ((1 + FastMath.exp(-d * (x - e))) * (1 + FastMath.exp(-f * (x - g))));
    }
}